<c:if test="true"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:nxl="http://nuxeo.org/nxforms/layout"
  xmlns:nxp="http://nuxeo.org/nxweb/pdf"
  xmlns:nxd="http://nuxeo.org/nxweb/document"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<c:if test="#{nxl:isLikePlainMode(widget.mode)}">
  <nxu:set var="numberOfSubWidgets"
    value="#{fn:length(widget.subWidgets)}" cache="true">
    <nxu:inputList value="#{fieldOrValue}" model="model"
      rendered="#{not empty field}">
      <nxl:subWidget>
        <nxl:widget widget="#{widget}" value="#{model.rowData}" />
        <h:outputText value=", "
          rendered="#{model.rowIndex != (model.rowCount-1) or widgetIndex != (numberOfSubWidgets-1)}" />
      </nxl:subWidget>
    </nxu:inputList>
  </nxu:set>
</c:if>
<c:if test="#{widget.mode == 'pdf'}">
  <nxp:html>
    <nxu:set var="numberOfSubWidgets"
      value="#{fn:length(widget.subWidgets)}" cache="true">
      <nxu:inputList value="#{fieldOrValue}" model="model"
        rendered="#{not empty field}">
        <nxl:subWidget>
          <nxl:widget widget="#{widget}" value="#{model.rowData}" />
          <h:outputText value=", "
            rendered="#{model.rowIndex != (model.rowCount-1) or widgetIndex != (numberOfSubWidgets-1)}" />
        </nxl:subWidget>
      </nxu:inputList>
    </nxu:set>
  </nxp:html>
</c:if>
<c:if test="#{nxl:isLikeViewMode(widget.mode) or widget.mode == 'edit'}">

  <c:set var="displaySubLabels" value="#{not widgetProperty_hideSubLabels}" />
  <c:set var="isEditMode" value="#{widget.mode == 'edit'}" />
  <c:set var="propValueForTemplate"
    value="#{widget.fieldDefinitions[0].propertyName}" />
  <c:set var="templateValue"
    value="#{nxu:test(empty widgetProperty_listTemplateItem, nxd:propertyDefaultValue(propValueForTemplate), widgetProperty_listTemplateItem)}" />
  <c:set var="showActions"
    value="#{isEditMode and (not widgetProperty_hideDeleteButton or widgetProperty_orderable)}" />
  <nxu:set var="listClientId" value="#{nxu:componentAbsoluteId(component, widget.id).substring(1)}">

  <div id="#{listClientId}_panel" class="widgetPanel listWidgetPanel table-overflow #{widgetProperty_styleClass}">

      <c:choose>

        <c:when test="#{widgetProperty_display == 'table'}">
          <table class="dataTable widgetTable listWidgetTable #{widgetProperty_styleClass}">
            <thead>
              <ui:fragment rendered="#{displaySubLabels and (isEditMode or not empty fieldOrValue)}">
                <tr>
                  <c:if test="#{showActions}">
                    <th class="boldColumn"></th>
                  </c:if>
                  <nxl:subWidget>
                    <th class="boldColumn">
                      <ui:include src="/widgets/incl/widget_label_template.xhtml">
                        <ui:param name="labelStyleClass"
                          value="boldLabel #{widgetProperty_subLabelStyleClass}" />
                      </ui:include>
                    </th>
                  </nxl:subWidget>
                </tr>
              </ui:fragment>
            </thead>
            <tbody>
              <nxu:jsInputList value="#{fieldOrValue}"
                id="#{widget.id}"
                model="model"
                template="#{templateValue}"
                required="#{widgetProperty_required}"
                removeEmpty="#{widgetProperty_removeEmpty}"
                number="#{widgetProperty_number}"
                diff="#{widgetProperty_diff}"
                rendered="#{isEditMode or not empty fieldOrValue}">
                <nxu:validateDocumentConstraint handleSubProperties="false" />

                <tr class="#{model.rowIndex % 2 == 0 ? 'dataRowEven': 'dataRowOdd'} listItem">
                  <td style="display:none;">
                    <h:inputHidden>
                      <f:passThroughAttribute name="name" value="#{listClientId}:#{isListTemplate ? 'TEMPLATE_INDEX_MARKER:': ''}rowIndex[]" />
                      <f:attribute name="value" value="#{isListTemplate ? 'TEMPLATE_INDEX_MARKER' : model.rowIndex}"/>
                    </h:inputHidden>
                  </td>
                  <c:if test="#{showActions}">
                    <td class="listWidgetActions">
                      <ui:include src="/widgets/js_list_widget_template_actions.xhtml" />
                    </td>
                  </c:if>
                  <nxl:subWidget>
                    <td class="fieldColumn">
                      <nxl:widget widget="#{widget}" value="#{model.rowData}"
                        onclick="#{widgetProperty_onclick}" onchange="#{widgetProperty_onchange}" />
                    </td>
                  </nxl:subWidget>
                </tr>
              </nxu:jsInputList>
              <ui:fragment rendered="#{isEditMode and not widgetProperty_hideAddButton}">
                <tr>
                  <td>
                    <a id="#{listClientId}_add" class="button smallButton listWidgetActionAdd" href="#nogo"
                       onclick="return nuxeo.utils.addFromListTemplate('#{listClientId}', jQuery(this).closest('tr').prev())">
                      <h:outputText value="#{nxu:test(empty widgetProperty_addLabel, messages['command.add'], nxu:test(widget.translated, messages[widgetProperty_addLabel], widgetProperty_addLabel))}" />
                    </a>
                  </td>
                </tr>
              </ui:fragment>
            </tbody>
          </table>
        </c:when>

        <c:when test="#{widgetProperty_display == 'inline'}">
          <table class="widgetTable listWidgetTable #{widgetProperty_styleClass}">
            <tbody>
              <nxu:jsInputList value="#{fieldOrValue}"
                id="#{widget.id}"
                model="model"
                template="#{templateValue}"
                required="#{widgetProperty_required}"
                removeEmpty="#{widgetProperty_removeEmpty}"
                number="#{widgetProperty_number}"
                diff="#{widgetProperty_diff}"
                rendered="#{isEditMode or not empty fieldOrValue}">
                <nxu:validateDocumentConstraint handleSubProperties="false" />
                <tr class="listItem">
                  <td style="display:none;">
                    <h:inputHidden>
                      <f:passThroughAttribute name="name" value="#{listClientId}:#{isListTemplate ? 'TEMPLATE_INDEX_MARKER:': ''}rowIndex[]" />
                      <f:attribute name="value" value="#{isListTemplate ? 'TEMPLATE_INDEX_MARKER' : model.rowIndex}"/>
                    </h:inputHidden>
                  </td>
                  <c:if test="#{showActions}">
                    <td class="listWidgetActions">
                      <ui:include src="/widgets/js_list_widget_template_actions.xhtml" />
                    </td>
                  </c:if>
                  <nxl:subWidget>
                    <c:if test="#{displaySubLabels}">
                      <td class="boldColumn listWidgetInlineDisplay">
                        <h:panelGroup rendered="#{model.rowIndex == 0}">
                          <ui:include src="/widgets/incl/widget_label_template.xhtml" />
                        </h:panelGroup>
                      </td>
                    </c:if>
                    <td class="fieldColumn">
                      <nxl:widget widget="#{widget}" value="#{model.rowData}"
                        onclick="#{widgetProperty_onclick}" onchange="#{widgetProperty_onchange}" />
                    </td>
                  </nxl:subWidget>
                </tr>
              </nxu:jsInputList>
              <ui:fragment rendered="#{isEditMode and not widgetProperty_hideAddButton}">
                <tr>
                  <td>
                    <a id="#{listClientId}_add" class="button smallButton listWidgetActionAdd" href="#nogo"
                       onclick="return nuxeo.utils.addFromListTemplate('#{listClientId}', jQuery(this).closest('tr').prev())">
                      <h:outputText value="#{nxu:test(empty widgetProperty_addLabel, messages['command.add'], nxu:test(widget.translated, messages[widgetProperty_addLabel], widgetProperty_addLabel))}" />
                    </a>
                  </td>
                </tr>
              </ui:fragment>
            </tbody>
          </table>
        </c:when>

        <c:when test="#{widgetProperty_display == 'block_top'}">
          <nxu:jsInputList value="#{fieldOrValue}"
            id="#{widget.id}"
            model="model"
            template="#{templateValue}"
            required="#{widgetProperty_required}"
            removeEmpty="#{widgetProperty_removeEmpty}"
            number="#{widgetProperty_number}"
            diff="#{widgetProperty_diff}"
            rendered="#{isEditMode or not empty fieldOrValue}">
            <nxu:validateDocumentConstraint handleSubProperties="false" />
            <h:panelGrid columns="#{isEditMode and showActions?2:1}" styleClass="listItem">
              <h:inputHidden>
                <f:passThroughAttribute name="name" value="#{listClientId}:#{isListTemplate ? 'TEMPLATE_INDEX_MARKER:': ''}rowIndex[]" />
                <f:attribute name="value" value="#{isListTemplate ? 'TEMPLATE_INDEX_MARKER' : model.rowIndex}"/>
              </h:inputHidden>
              <c:if test="#{showActions}">
                <h:panelGroup styleClass="listWidgetActionsTable" id="#{widget.id}_actions">
                  <ui:include src="/widgets/js_list_widget_template_actions.xhtml" />
                </h:panelGroup>
              </c:if>
              <h:panelGroup>
                <table>
                  <tbody>
                    <nxl:subWidget>
                      <tr>
                        <c:if test="#{displaySubLabels}">
                          <td class="boldColumn">
                            <ui:include src="/widgets/incl/widget_label_template.xhtml">
                              <ui:param name="labelStyleClass"
                                value="boldLabel #{widgetProperty_subLabelStyleClass}" />
                            </ui:include>
                            <h:outputText value=" " />
                          </td>
                        </c:if>
                      </tr>
                      <tr>
                        <td class="fieldColumn">
                          <nxl:widget widget="#{widget}" value="#{model.rowData}"
                            onclick="#{widgetProperty_onclick}" onchange="#{widgetProperty_onchange}" />
                        </td>
                      </tr>
                    </nxl:subWidget>
                  </tbody>
                </table>
              </h:panelGroup>
            </h:panelGrid>
          </nxu:jsInputList>

          <ui:fragment rendered="#{isEditMode and not widgetProperty_hideAddButton}">
            <a id="#{listClientId}_add" class="button smallButton listWidgetActionAdd" href="#nogo"
               onclick="return nuxeo.utils.addFromListTemplate('#{listClientId}', jQuery(this).prev());">
              <h:outputText value="#{nxu:test(empty widgetProperty_addLabel, messages['command.add'], nxu:test(widget.translated, messages[widgetProperty_addLabel], widgetProperty_addLabel))}" />
            </a>
          </ui:fragment>
        </c:when>

        <c:otherwise>
          <nxu:jsInputList value="#{fieldOrValue}"
            id="#{widget.id}"
            model="model"
            template="#{templateValue}"
            required="#{widgetProperty_required}"
            removeEmpty="#{widgetProperty_removeEmpty}"
            number="#{widgetProperty_number}"
            diff="#{widgetProperty_diff}"
            rendered="#{isEditMode or not empty fieldOrValue}">
            <nxu:validateDocumentConstraint handleSubProperties="false" />
            <h:panelGrid columns="#{isEditMode and showActions?2:1}" styleClass="listItem">
              <c:if test="#{showActions}">
                <h:panelGroup styleClass="listWidgetActionsTable" id="#{widget.id}_actions">
                  <ui:include src="/widgets/js_list_widget_template_actions.xhtml" />
                </h:panelGroup>
              </c:if>
              <h:panelGroup>
                <h:inputHidden>
                  <f:passThroughAttribute name="name" value="#{listClientId}:#{isListTemplate ? 'TEMPLATE_INDEX_MARKER:': ''}rowIndex[]" />
                  <f:attribute name="value" value="#{isListTemplate ? 'TEMPLATE_INDEX_MARKER' : model.rowIndex}"/>
                </h:inputHidden>
                <table>
                  <tbody>
                    <nxl:subWidget>
                      <tr>
                        <c:if test="#{displaySubLabels}">
                          <td class="boldColumn">
                            <ui:include src="/widgets/incl/widget_label_template.xhtml">
                              <ui:param name="labelStyleClass"
                                value="boldLabel #{widgetProperty_subLabelStyleClass}" />
                            </ui:include>
                            <h:outputText value=" " />
                          </td>
                        </c:if>
                        <td class="fieldColumn">
                          <nxl:widget widget="#{widget}" value="#{model.rowData}"
                            onclick="#{widgetProperty_onclick}" onchange="#{widgetProperty_onchange}" />
                        </td>
                      </tr>
                    </nxl:subWidget>
                  </tbody>
                </table>
              </h:panelGroup>
            </h:panelGrid>
          </nxu:jsInputList>

          <ui:fragment rendered="#{isEditMode and not widgetProperty_hideAddButton}">
            <a id="#{listClientId}_add" class="button smallButton listWidgetActionAdd" href="#nogo"
               onclick="return nuxeo.utils.addFromListTemplate('#{listClientId}', jQuery(this).prev());">
              <h:outputText value="#{nxu:test(empty widgetProperty_addLabel, messages['command.add'], nxu:test(widget.translated, messages[widgetProperty_addLabel], widgetProperty_addLabel))}" />
            </a>
          </ui:fragment>
        </c:otherwise>

      </c:choose>

      <h:message styleClass="errorMessage" for="#{widget.id}"
        id="#{widget.id}_message" />

  </div>
  </nxu:set>

</c:if>
</c:if>